-- 加载C++模块
require("LuaTableWrapper")

-- 使用LActor接口获取表
local actor = {} -- 假设这是一个actor对象
local myTable = LActor.getActorTableVar(actor)

-- 测试.访问方式
myTable.name = "Lua Table Wrapper"
myTable.version = 1.0
myTable.enabled = true

-- 测试[]访问方式
myTable[1] = "First item"
myTable[2] = 12345
myTable[3] = 3.14159

-- 测试置空字段
myTable.nullField = "This will be deleted"
myTable.nullField = nil

-- 测试嵌套表
myTable.nested = {
    key1 = "nested value",
    key2 = 42,
    key3 = {
        subkey1 = "deeply nested",
        subkey2 = 3.14
    }
}

-- 测试数组式嵌套表
myTable.array = {
    "first",
    "second",
    {
        "nested in array",
        key = "mixed type"
    }
}

-- 打印结果
print("Name:", myTable.name)
print("Version:", myTable.version)
print("Enabled:", myTable.enabled)
print("Item 1:", myTable[1])
print("Item 2:", myTable[2])
print("Item 3:", myTable[3])
print("Null Field:", myTable.nullField)

-- 打印嵌套表内容
print("Nested key1:", myTable.nested.key1)
print("Nested key3.subkey1:", myTable.nested.key3.subkey1)
print("Array[1]:", myTable.array[1])
print("Array[3][1]:", myTable.array[3][1])
print("Array[3].key:", myTable.array[3].key)

-- 测试不存在的键
print("Non-existent key:", myTable.nonExistentKey)

-- 测试pairs遍历
print("\nPairs遍历:")
for k, v in pairs(myTable) do
    print(k, "=>", v)
end

-- 测试ipairs遍历
print("\nIpairs遍历:")
for i, v in ipairs(myTable) do
    print(i, "=>", v)
end

-- 测试长度操作符
print("\n表长度:", #myTable)


local lua_tbl1 = LActor.getActorTableVar(actor)
-- 置空单个字段
lua_tbl1.test_tbl1 = nil

-- 重置整个表为空表
lua_tbl1 = {} -- 这会保留表引用但清空所有内容

-- 完全置空表(需要额外处理)
lua_tbl1 = nil -- 这会移除表的引用